<?php
namespace app\api\controller;

use app\api\logic\ConfigLogic;
use app\common\model\user\UserProtocol;
use think\response\Json;

/**
 * 配置控制器
 * Class ConfigController
 * @package app\api\controller
 */
class ConfigController extends BaseApiController
{

    public $notNeedLogin = ['index', 'getLocation', 'getProtocol', 'getAppConfig'];

    public function index()
    {
    }

    /**
     * 获取定位
     * @return \support\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getLocation()
    {
        $result = ConfigLogic::getLocation();
        if ($result['code'] == 200) {
            return $this->data($result['data']);
        }
        return $this->fail('', [], 0, 0);
    }

    /**
     * 全局配置
     * @return \support\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getAppConfig()
    {
        $result = ConfigLogic::getConfigData();
        return $this->data($result);
    }

    /**
     * 获取表单配置
     * @return \support\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getFormList()
    {
        $result = ConfigLogic::getTreeFormList();
        return $this->data($result);
    }

    /**
     * 获取协议
     * @return \support\Response
     */
    public function getProtocol()
    {
        $type = $this->request->get('type');
        $result = ConfigLogic::getPolicyByType($type);
        return $this->data($result);
    }

    /**
     * 获取我的授权协议
     * @return \support\Response
     */
    public function getMyProtocol()
    {
        $id = (int)$this->request->get('id');
        $info = UserProtocol::where([
            ['id','=',$id],
        ])->findOrEmpty()->toArray();
        return $this->data($info);
    }


}